<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    




    <script>
        var str = 'abcdacbabcbababcbabcabd'
        // 拆成数组
        var arr = str.split('')
        console.log(arr);
        // 统计个数以对象的形式返回
        var res = arr.reduce(function(pre,cur){
            if(pre[cur]){
                pre[cur] += 1
            }else{
                pre[cur] = 1
            }
            return pre
        },{})
        console.log(res);
        
        
    </script>
</body>
</html>